# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 自定义元类.py
Author: kij
Create Date: 2021/2/18
-------------------------------------------------
"""


# 继承至type
class Klass(type):
	def __init__(self, class_name, class_bases, class_dic):
		print("欢迎来到Klass")
		super(Klass, self).__init__(class_name, class_bases, class_dic)

	def __call__(self, *args, **kwargs):  # Kijlee('张坤',age=30)
		print("调用了call方法")
		print(self)  # Kijlee
		print(args)  # name = (张坤,)
		print(kwargs)  # kwargs = {'age':30}
		# 第一件事 先创造一个对象object
		obj = object.__new__(self)
		# 第二件事 初始化obj
		self.__init__(obj, *args, **kwargs)
		# 第三件事 返回obj
		return obj


class Kijlee(object, metaclass=Klass):
	def __init__(self, name, age):
		self.name = name
		self.age = age

	def talk(self):
		print("%s 在说话我%s岁了" % (self.name, self.age))


kij = Kijlee('张坤', age=30)  # 相当于调用__call__
print(kij.__dict__)
kij.talk()
